/*
 *说明：QUARTZ 增加/修改脚本
 *
 *@author liuxun 2012-11-28
 */

var opeForm;
var operationType;

$(function() {
	opeForm = $('#opeForm');
	operationType = $('#operationType').val();

	if (operationType == 0) {
		opeForm.url = 'QRTZ!doInsert.do';

	} else if (operationType == 1) {
		opeForm.url = 'QRTZ!doUpdate.do';

	}

	$('#repeatCount').change(changeRepeatCount);
	$('#okBtn').click(doOk);
	$('#cancelBtn').click(closeWin);
	
	changeRepeatCount();
});

// 
function changeRepeatCount() {
	var repeatCount = $('#repeatCount').val();
	if (repeatCount == '0') {	// only one
		$('#repeatInterval').attr('disabled', true);
		$('#repeatInterval').val('');
	} else if (repeatCount == '-1') {	//repeat
		$('#repeatInterval').attr('disabled', false);
	}
}

// 保存按钮操作
function doOk() {

	var validateResult = opeForm.form('validate');

	if (!validateResult) {
		showInfoWin('请正确填写信息!');
		return;
	}

	var options = {
		url : opeForm.url,
		type : 'post',
		success : function(data) {
			getOpenerWin().afterOK();

			if (operationType == '0') {
				showInfoWin('操作成功!', refreshWin);

			} else {
				showInfoWin('操作成功!', function() {
					window.close();
				});
			}
		}
	};

	opeForm.ajaxSubmit(options);
}
